package iso
{
	import com.fminutes.vinciIsometric.core.IsoMapItem;
	import com.fminutes.vinciIsometric.core.IsoPosition;
	import com.fminutes.vinciIsometric.core.IsoUtils;
	import com.fminutes.vinciIsometric.core.IsoWorld;
	
	import flash.geom.Point;
	import flash.geom.Vector3D;
	
	public class CityIsoWorld extends IsoWorld
	{	
		public function CityIsoWorld(xNum:int=100, zNum:int=100, size:int=16, showNum:Number=2)
		{
			super(xNum, zNum, size, showNum);
		}
		
		public function removeWall(position:IsoPosition):void
		{
			var isoMapItem:IsoMapItem = getIsoMapItem(position);
			if (isoMapItem != null) 
			{
				var isos:Array = isoMapItem.isoList;
				for (var i:int = 0; i < isos.length; i++) 
				{
					removeFromWorld(isos[i]);
				}
			}
		}
		
		public function isPositionInIsoWorld(position:IsoPosition):Boolean
		{
			return 0 <= position.x && position.x < xNum && 0 <= position.z && position.z < zNum;
		}
		
		public function addWall(wall:WallIsoObject, point:Point):void
		{
			if (isPointInIsoWorld(point))
			{
				wall.xyz = IsoUtils.screenToIso(point);
				addToWorld(wall);
			}
		}
		
		public function isPointInIsoWorld(point:Point):Boolean
		{
			var position:IsoPosition = PointToPostion(point);
			return isPositionInIsoWorld(position);
		}
		
		public function PointToPostion(point:Point):IsoPosition
		{
			var vector3D:Vector3D = IsoUtils.screenToIso(point);
			return new IsoPosition(Math.floor(vector3D.x/size), Math.floor(vector3D.z/size));
		}
		
		public function removeWallWithWallIsoObject(wall:WallIsoObject):void
		{
			removeFromWorld(wall);
		}
		
		/**
		 *是否有isoobject在position位置 
		 * @return 
		 * 
		 */
		public function hasIsoObjectUnderPosition(position:IsoPosition):Boolean
		{
			return null != getIsoMapItem(position) && 0 != getIsoMapItem(position).isoList.length;
		}
	}
}